<?php

namespace LaraPress\Config;

use LaraPress\Config\ReduxBuilder;
use Redux;

class LaraPressCms
{
    public $redux;

    public function __construct()
    {
        if (!class_exists('ReduxFramework')) {
            return;
        }
        $this->init();
    }

    static function get_option($key, $default = null)
    {
        return Redux::get_option('lara_press_cms', $key, $default);
    }

    public function init()
    {
        $config = [
            "opt_name" => "lara_press_cms",
            "display_name" => "Larapress App Cms设置",
            "menu_title" => "Larapress App Cms设置",
            "page_slug" => "lara_press_cms",
            "menu_icon" => "dashicons-admin-generic",
        ];
        $sections = [
            [
                "type" => "section",
                "title" => "默认设置",
                "id" => "default_settings",
                "fields" => [
                    [
                        "type" => "media",
                        "title" => "默认封面",
                        "id" => "cover",
                        "desc" => "如果文章没设置封面并且文章中也没有图片，将使用这里设置的图片当做封面"
                    ],
                    [
                        "type" => "media",
                        "title" => "分类默认封面",
                        "id" => "category_cover",
                        "desc" => "如果文章没设置封面并且文章中也没有图片，将使用这里设置的图片当做封面"
                    ]
                ]
            ],
            [
                "type" => "section",
                "title" => "首页排版设置",
                "id" => "home_layout",
                "icon" => "el el-home",
                "fields" => [
                    [
                        "id" => "home_layout_style",
                        "type" => "select",
                        "title" => "首页排版样式",
                        "options" => [
                            "style1" => "样式1",
                        ],
                        "default" => "style1",
                        "placeholder" => "请选择首页排版样式",
                        "desc" => "首页排版样式，用于设置首页的排版样式，不知道长什么样式的可以查看相关文档中的截图。",
                    ],
                    [
                        "id" => "home_show_category",
                        "type" => "select",
                        "title" => "首页展示的分类",
                        "data" => "categories",
                        "multi" => true,
                        "sortable" => true,
                        "placeholder" => "请选择首页展示的分类",
                        "desc" => "首页展示的分类，拖动可排序，不同样式下展示方式不同，详见相关文档中的截图。",
                    ],
                    [
                        "id" => "show_top_module",
                        "type" => "switch",
                        "title" => "是否展示置顶模块",
                        "default" => true,
                        "placeholder" => "请选择是否展示置顶模块",
                        "desc" => "在不同的样式下，置顶模块的展示方式不同，详见相关文档中的截图。",
                    ]
                ],
            ],
            [
                "type" => "section",
                "title" => "横排图文样式",
                "id" => "row_img_list",
                "desc" => "此类样式为图片和内容在一行显示",
                "icon" => "el el-tasks",
                "fields" => [
                    ReduxFieldBuilder::createButtonSet(
                        'list_display_data',
                        '列表展示数据',
                        [
                            "author" => "作者",
                            "author_avatar" => "作者头像",
                            "category" => "分类",
                            "date" => "日期",
                            "excerpt" => "摘要",
                        ],
                        ["author", "author_avatar", "category", "date", "excerpt"],
                        true
                    ),

                    ReduxFieldBuilder::createButtonSet(
                        'image_position',
                        '图片位置',
                        ['left' => '左', 'right' => '右'],
                        'left',
                        false
                    ),
                    ReduxFieldBuilder::createButtonSet(
                        'image_display',
                        '图片位置',
                        ['auto' => '自动', 'one' => '固定一张'],
                        'left',
                        false,
                        "自动模式下如果文中图片数量大于1，则图片显示在内容下方并且多张图片并排显示，固定一张模式下只显示一张图片，图片显示在【图片位置】中设置的位置"
                    ),
                ],
            ]
        ];
        $this->redux = new ReduxBuilder($config, $sections);
    }
}
